<template>
  <div class="row" ref="col" :class="rowClass" :style="rowStyle">
    <slot />
  </div>
</template>

<script lang="ts">
import { ref, provide, computed } from 'vue'
export default {
  props: {
    gutter: {
      type: [Number, String],
    },
    align: {
      type: String,
      validator(value) {
        return ['left', 'right', 'center'].includes(value)
      },
    },
  },
  setup(props, context) {
    provide('gutter', props.gutter)
    const rowStyle = computed(() => {
      return {
        marginLeft: -props.gutter / 2 + 'px',
        marginRight: -props.gutter / 2 + 'px',
      }
    })
    const rowClass = computed(() => {
      return [props.align && `align-${props.align}`]
    })
    return { rowStyle, rowClass }
  },
}
</script>

<style lang="scss" scoped>
.row {
  display: flex;
  flex-wrap: wrap;
  &.align-right {
    justify-content: flex-end;
  }
  &.align-left {
    justify-content: flex-start;
  }
  &.align-center {
    justify-content: center;
  }
}
</style>
